class Login {

  static constraints = {
    password(maxSize:64)
    role(maxSize:64)
  }

  String password
  String role

  public static String getRoleForPasswordHash(String hash, String nonce) {
    if(logins == null) {
      logins = Login.list()
    }

    // Not terribly efficient, but will work fine for just a few
    // passwords. You will have to come up with something more
    // sophisticated if it's more than just a few and there's a
    // lot of traffic.
    for(Login l in logins) {
      if(Util.hexSHA1(l.password + nonce) == hash) {
        return l.role
      }
    }

    return null
  }

  private static List<Login> logins = null
}
